package cn.xiangxu.login.service;

import java.io.Serializable;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import cn.xiangxu.login.dao.AdminDao;
//import cn.xiangxu.login.dao.AdminDaoSpringJdbcImpl;
import cn.xiangxu.login.entity.Admin;

@Service("loginService")
public class LoginServiceImpl implements Serializable, LoginService {

//	@Resource(name="adminDao")  // 如果是 adminDao 就是用springJdbc连接数据库
	@Resource(name="adminDaoT") // 如果是 adminDao1 就是利用Mybatis连接数据
	private AdminDao ad;
	
	public Admin serviceLogin(String name, String password) {
		Admin admin = null;
		admin = ad.findByName(name);
		if(admin == null) {
//			用户名错误：抛出应用异常
			throw new YongHuCaoZuoException("用户名错误");
		}
		if(!password.equals(admin.getPassword())) {
//			密码错误：抛出应用异常
			throw new YongHuCaoZuoException("密码错误");
		}
		return admin;
	}

}
